package shapes.shapes2D.distribution.trigo 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import samples.BaseSample;
	import shapes.shapes2D.Arc;
	import utils.GeomUtils;
	
	/**
	 * @author Nicolas Barradeau
	 * http://en.nicoptere.net
	 */
	public class Pythagora extends BaseSample
	{
		
		private var radius:Number = 250;
		private var angle:Number = 0;
		private var osc:Number = 0;
		private var arc:Arc;
		private var arc0:Arc;
		private var p:Point;
		
		public function Pythagora() 
		{
			
			
			addEventListener( Event.ENTER_FRAME, update );
			
			p = new Point( sw / 2, sh / 2 );
			arc = new Arc( p, radius * .5, 0, 45, 180 );
			arc0 = new Arc( p, radius * .5, 0, 45, 180 );
			
		}
		
		private function update(e:Event):void 
		{
			var cos:Number = Math.cos( angle );
			var sin:Number = Math.sin( angle );
			
			
			
			osc += Math.PI / 180;
			angle = GeomUtils.angle( p, new Point( _stage.mouseX, _stage.mouseY ) );
			
			
			graphics.clear();
			graphics.lineStyle( 2, 0xFFFFFF );
			graphics.drawCircle(  p.x, p.y, radius );
			
			graphics.lineStyle( 3, 0x00FF00 );
			
			var degres:Number = ( angle * 180 / Math.PI ) % 360;
			degres = ( degres > 180 ) ? ( degres - 360 ) : degres;
			arc.endAngle = degres;
			arc.draw( graphics );
			
			arc0.startAngle = degres;
			arc0.endAngle = (degres > 0 ) ? 180 : - 180;
			arc0.radius = radius * .75;
			arc0.draw( graphics );
			
			
			graphics.lineStyle( 3, 0xFFFF00 );
			graphics.moveTo( p.x, p.y );
			graphics.lineTo( p.x + cos * radius, p.y );
			graphics.lineStyle( 3, 0xFF6000 );
			graphics.lineTo( p.x + cos * radius, p.y + sin * radius );
			
			graphics.lineStyle( 3, 0x0000FF );
			graphics.moveTo( p.x, p.y );
			graphics.lineTo( p.x, p.y + sin * radius );
			graphics.lineStyle( 3, 0x8000FF );
			graphics.lineTo( p.x + cos * radius, p.y + sin * radius );
			
			
			graphics.lineStyle( 3, 0xFF0000 );
			graphics.moveTo(  p.x, p.y );
			graphics.lineTo( p.x + cos * radius, p.y  + sin * radius );
			
			
			
			
			
			
			graphics.lineStyle(0,0,0);
			graphics.beginFill( 0xFFFFFF );
			graphics.drawCircle( p.x + cos * radius, p.y + radius + 25, 4 );
			graphics.drawCircle( p.x + radius + 25, p.y  + sin * radius, 4 );
			graphics.drawCircle( p.x + cos * radius, p.y  + sin * radius, 10 );
			graphics.drawCircle(  p.x, p.y, 10 );
			
			graphics.endFill();
			
			
			graphics.beginFill( 0xFF00FF );
			
			var hyp:Number = 1 / radius;
			
			
			
			var _p:Point = new Point( p.x, p.y )
			graphics.drawCircle( _p.x, _p.y, 5 );
			
			
		}
		
	}

}